﻿using CrystalDecisions.CrystalReports.Engine;
using CrystalDecisions.Shared;
using DBUtility;
using gfLibrary;
using IYAKASAPortal.Services;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Model;
using System.Threading;

namespace IYAKASAPortal.PrintAll
{
    public partial class Print_SQPZ : System.Web.UI.Page
    {

     
        private ReportDocument document;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
              
            }
        }

        private ReportDocument BindDoc(string strKey,string strPath)
        {
            RESULT_VEHICLE_INFO_BLL bll = new RESULT_VEHICLE_INFO_BLL();
            var vehicleInfo = bll.GetModel(strKey);

            document = new ReportDocument();
            document.Load(strPath);
            rpt.DsAJ_JDCPZSQB ds = new rpt.DsAJ_JDCPZSQB();
            DataRow dr = ds.Tables["dtBase"].NewRow();

            dr["XM"] = vehicleInfo.SYR;
            dr["YZBM"] = vehicleInfo.YZBH;
            dr["YJDZ"] = vehicleInfo.LXDZ;
            dr["SJHM"] = vehicleInfo.LXDH;
            dr["DLR_XM"] = vehicleInfo.DLRMC;
            dr["DLR_SJHM"] = vehicleInfo.DLRLXDH;
            dr["HPZL"] = vehicleInfo.HPZL;
            dr["HPHM"] = vehicleInfo.HPHM;
            dr["Y"] = DateTime.Now.Year;
            dr["M"] = DateTime.Now.Month;
            dr["D"] = DateTime.Now.Day;

            ds.Tables["dtBase"].Rows.Add(dr);
            document.SetDataSource(ds);
            return document;
        }

        protected override void OnInit(EventArgs e)
        {
            if (Request["UniqueKey"] != null && Request["UniqueKey"].ToString() != "")
            {
                BindReportData(Request["UniqueKey"].ToString());
            }
        }

        private void BindReportData(string strKey)
        {
            string strPathAJ = Server.MapPath("~/rpt/CrystalReport_JDCPZSQ.rpt");
            document = BindDoc(strKey, strPathAJ);
            CRAJ.ReportSource = document;
            CRAJ.DataBind();
            CRAJ.RefreshReport();           
        }


        protected override void OnUnload(EventArgs e)
        {
            if (document != null)
            {
                document.Dispose();
            }
            
            base.OnUnload(e);
        }
    }
}